package controller;

import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;

import javax.naming.InitialContext;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.sql.DataSource;

import BizLogic.FacilityManager;
import BizLogic.FacilityTypeManager;
import BizLogic.PriorityManager;

import model.Facility;
import model.FacilityType;
import model.Priority;

import dao.DAOFactory;
import dao.FacilityDAO;
import dao.FacilityTypeDAO;
import dao.PriorityDAO;

/**
 * Servlet implementation class MakeBookingServlet
 */
@WebServlet("/LoadBookingServlet")
public class LoadBookingServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       private String result="";
    /**
     * @see HttpServlet#HttpServlet()
     */
    public LoadBookingServlet() {
        super();
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		doProcess(request,response);
	}

	private void doProcess(HttpServletRequest request,
			HttpServletResponse response)throws ServletException,IOException {
		// TODO Auto-generated method stub
		try {
				
			ArrayList<String> Priority=new PriorityManager().getPriorities();
			ArrayList<String> fType= new FacilityTypeManager().getFacilityTypeNames();
			ArrayList<String> facility=new FacilityManager().getFacilityNames();
			RequestDispatcher rd=request.getRequestDispatcher("MakeBooking.jsp");
			request.setAttribute("fType", fType);
			request.setAttribute("facility", facility);
			request.setAttribute("Priority", Priority);
			request.setAttribute("result", result);
			rd.forward(request, response);
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		try
		{
			result=request.getAttribute("result").toString();
			System.out.println("result"+result);
			doProcess(request,response);
			
		}
		catch(Exception ee)
		{doProcess(request,response);}	
	}

}
